package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.{ExecutionContext, Future}

class QtlDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
                      (implicit exec: ExecutionContext) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def getByTrait(tr: String): Future[Seq[QtlRow]] = {
    db.run(Qtl.filter(_.`trait` === tr).result)
  }

  def getAll: Future[Seq[QtlRow]] = {
    db.run(Qtl.result)
  }

  def getById(id: Int): Future[QtlRow] = {
    db.run(Qtl.filter(_.id === id).result.head)
  }

  def getByPos(chr:String,start:Int,end:Int) : Future[Seq[QtlRow]] ={
    db.run(Qtl.filter(_.chr === chr).filter(_.left <= start).filter(_.right >= end).result)
  }

}
